package com.ytjj.qmyx.admin.service.impl;

import com.github.pagehelper.PageHelper;
import com.ytjj.common.api.CommonPage;
import com.ytjj.common.exception.ApiException;
import com.ytjj.qmyx.admin.dao.GroupDetailsDao;
import com.ytjj.qmyx.admin.eunm.GroupEnums;
import com.ytjj.qmyx.admin.model.request.GroupDetailsReq;
import com.ytjj.qmyx.admin.model.request.GroupOrderReq;
import com.ytjj.qmyx.admin.model.request.PageRequest;
import com.ytjj.qmyx.admin.model.response.GroupOrderResp;
import com.ytjj.qmyx.admin.model.vo.GroupDetailsVO;
import com.ytjj.qmyx.admin.service.GroupDetailsService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

@Service
@AllArgsConstructor
public class GroupDetailsServiceImpl implements GroupDetailsService {

    private GroupDetailsDao groupDetailsDao;

    @Override
    public CommonPage<GroupDetailsVO> selectGroupList(GroupDetailsReq groupDetailsReq) {
        PageHelper.startPage(groupDetailsReq.getPageNum(), groupDetailsReq.getPageSize());
        List<GroupDetailsVO> groupSelectVOList = groupDetailsDao.selectGroupList(groupDetailsReq);
        return CommonPage.restPage(groupSelectVOList);
    }

    @Override
    public CommonPage<GroupDetailsVO> detailById(Integer groupId) {
        List<GroupDetailsVO> groupDetailVOList = groupDetailsDao.detailById(groupId);
        if(CollectionUtils.isEmpty(groupDetailVOList)){
            throw new ApiException(GroupEnums.PT_INFO_IS_NULL.getMessage());
        }
        PageRequest pageRequest = new PageRequest();
        PageHelper.startPage(pageRequest.getPageNum(), pageRequest.getPageSize());
        return CommonPage.restPage(groupDetailVOList);
    }

    @Override
    public CommonPage<GroupOrderResp> getGroupOrder(GroupOrderReq req) {
        PageHelper.startPage(req.getPageNum(), req.getPageSize());
        List<GroupOrderResp> list = groupDetailsDao.selectGroupOrder(req);
        CommonPage<GroupOrderResp> page = CommonPage.restPage(list);
        return page;
    }
}
